<?php

namespace App\Console\Commands;

use App\User;
use App\UserCoupon;
use Illuminate\Console\Command;

class Subscribe extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'user:subscribe';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        User::where('id','<',688)->chunk(50,function($user){
           foreach ($user as $v){

              /* $app = \EasyWeChat::officialAccount();
               $userinfo = $app->user->get($v->openid);
               if(isset($userinfo['subscribe'])&&$userinfo['subscribe']){
                   $this->info($v->id);
                   $v->subscribe=1;
                   $v->save();
               }*/
              if($v->team_level_id>0){
               $userCoupon= UserCoupon::where('id','>',545)->where('user_id',$v->id)->where('staus','!=',1)->first();
               if($userCoupon){
                   $userCoupon->staus=1;
                   $userCoupon->save();
                   $this->info($v->id);
               }
              }
           }
        });
    }
}
